<template>
  <button @click="switchComponent">切换</button>
  <KeepAlive>
    <component :is="curComponent"></component>
  </KeepAlive>
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import CacheOneView from './CacheOneView.vue'
import CacheTwoView from './CacheTwoView.vue'
const curComponent = shallowRef(CacheOneView)
const switchComponent = () => {
  curComponent.value = (curComponent.value === CacheOneView) ? CacheTwoView : CacheOneView
}

</script>
